package cn.kbyue.doublecachedemo.controller;

import cn.kbyue.doublecachedemo.entity.Order;
import cn.kbyue.doublecachedemo.service.CacheServiceImpl;
import lombok.AllArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/cache")
@AllArgsConstructor
public class CacheController {

    private final CacheServiceImpl cacheService;

    @GetMapping("/{id}")
    public ResponseEntity<Order> get(@PathVariable("id") Long id) {
        Order order = cacheService.getOrderById(id);
        return ResponseEntity.ok(order);
    }

    @PutMapping("/update")
    public ResponseEntity<Order>update(@RequestBody Order order) {
        Order updateOrder = cacheService.updateOrder(order);
        return ResponseEntity.ok(updateOrder);
    }

    @DeleteMapping("/{id}")
    public ResponseEntity<String> delete(@PathVariable("id") Long id) {
        cacheService.deleteOrder(id);
        return ResponseEntity.ok("删除完成");
    }

}
